// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
const socketManage=require("../socketManage")
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        pokers:{
            default:[],
            type:cc.Sprite
        },
        cardPrefab:{
            default: null,
            type:cc.Prefab
        },
        index:0,
        myPokers:[]
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // this.pokers=this.node.getComponentsInChildren(cc.Sprite);
        // this.node.on("isClick",(msg)=>{})

    },

    start () {

        // console.log(this.pokers.length);
        // let offset =-160
        // for(let i=0;i<this.pokers.length;i++){
        //     console.log(this.pokers[i].node.group)
        //     if(this.pokers[i].node.group=="poker"){
        //         this.pokers[i].node.position=this.pokers[i].node.position.add(cc.v2(offset,0));
        //         offset+=40
        //         //console.log(this.pokers[i].node.position)
        //     }
        // }
    },

    update (dt) {
        if(socketManage.desktop.length>0){
            let data=socketManage.desktop;
            let offset=-140;
            let myPokerNum=data.splice(0,13).sort((a,b)=>{
                return a-b;
            });
            console.log(data);
            for(let i=0;i<13;i++){
                this.myPokers.push(myPokerNum[i]);
                let currentPoker=cc.instantiate(this.cardPrefab);
                currentPoker.getComponent("poker").init(myPokerNum[i]);
                currentPoker.position=cc.v2(offset,0);
                offset+=30;
                currentPoker.parent=this.node;
            }
        }

    },
});
